package cn.ymz.observe;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

/**
 * 观察对象
 */
public class Subject extends Observable {

    private final static Subject INSTANCE = new Subject();
    private List<String> logs;

    private Subject() {
        logs = new ArrayList<>();
        addObserver(Observe.getInstance());
    }

    public static Subject getInstance() {
        return INSTANCE;
    }


    public List<String> getLogs() {
        return logs;
    }

    // 添加记录
    public void addLog(String log) {
        logs.add(log);
        this.makeChanged();
    }

    // 通知方法
    public void makeChanged() {
        setChanged();
        notifyObservers();
    }

}
